package set;

import java.util.Objects;

public class Car implements Comparable<Car> {
    private String name;
    private int price;


    public Car() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Car car = (Car) o;
        return Double.compare(car.price, price) == 0 && Objects.equals(name, car.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, price);
    }

    public Car(String name, int price) {
        this.name = name;
        this.price = price;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return price
     */
    public double getPrice() {
        return price;
    }

    /**
     * 设置
     *
     * @param price
     */
    public void setPrice(int price) {
        this.price = price;
    }

    public String toString() {
        return "Car{name = " + name + ", price = " + price + "}";
    }

    @Override
    public int compareTo(Car o) {
        System.out.println("this:" + this);
        System.out.println("o:" + o);
        return (int) (this.getPrice() - o.getPrice());
    }
}
